﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace A2DFramework.SessionService.Configuration
{
    public static class SessionConfiguration
    {
        public static string DESKey = "AaronDai";
        public static string MongoDBName;
        public static string MongoDBCollectionName = "Sessions";
        public static string[] SessionServerIdentities = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
        public static Dictionary<string, string> SessionIdentityMongoDBMap;

        static SessionConfiguration()
        {
            Dictionary<string, string> map = new Dictionary<string, string>();

            XElement root = XElement.Load(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "A2D.config"));

            root = root.Element("MongoDBSession");
            if (root == null)
                throw new Exception("MongoDBSession node not exists");

            foreach (var elm in root.Elements("IdentityMap"))
            {
                string identity = elm.Attribute("Identity").Value;
                string dbConnectionString = elm.Value;
                map[identity] = dbConnectionString;
            }

            SessionIdentityMongoDBMap = map;

            MongoDBName = root.Element("DbName").Value;
        }
    }
}
